/*
 * Copyright (C) 2009 Rob Cash
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * HourAndMinuteFormatter.java
 * 
 * Created on Jan 17, 2009 at 9:46:41 PM
 */

package org.robcash.apps.messagepopup.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Utility class for parsing and formatting date values using only the hours and
 * minutes
 * @author Rob
 */
public class HourAndMinuteFormatter {

    /**
     * Date formatter
     */
    private static DateFormat formatter = new SimpleDateFormat("HH:mm:00");

    /**
     * Parse a String into a date
     * @param input String to parse
     * @return Date
     * @throws IllegalArgumentException Thrown if input cannot be parse into a
     * date
     */
    public static Date parseTime(String input) throws IllegalArgumentException {
        try {
            return formatter.parse(input);
        }
        catch(ParseException e) {
            throw new IllegalArgumentException("Could not parse input as a time", e);
        }
    }

    /**
     * Print a time as a string
     * @param input Time to print
     * @return String representation of time
     */
    public static String printTime(Date input) {
        return formatter.format(input);
    }

}
